<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">考试名称(工种):</label>
        <div class="layui-input-inline" style="width: 250px">
            <select name="examineeSubject" id="examineeSubject" lay-filter="examineeSubject">
                <option value="理论考(电工作业)">理论考(电工作业)</option>
                <option value="理论考(焊接与热切割作业)">理论考(焊接与热切割作业)</option>
                <option value="理论考(高处作业)">理论考(高处作业)</option>
                <option value="理论考(制冷与空调作业)">理论考(制冷与空调作业)</option>
                <option value="理论考(高危行业)">理论考(高危行业)</option>
            </select>
        </div>
        <label class="layui-form-label" style="width: 60px">时间:</label>
        <div class="layui-input-inline">
            <input type="text" name="startTime" id="startTime"
                   class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" name="endTime" id="endTime"
                   class="layui-input">
        </div>
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn">查询</button>
        <div class="layui-input-inline" style="width: 120px">
            <a id="down" class="layui-btn layui-btn-radius" download="统计信息.csv" href="#">导出</a>
        </div>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var allStr;

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#startTime', //指定元素
            format: 'yyyy-MM-dd'
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#endTime', //指定元素
            format: 'yyyy-MM-dd'
        });
    });

    $(function () {
        var tableIns = createTable({
            url: 'list',
            cols: [[
                {field: 'numbers', title: '考试人数', width: 160}, {
                    field: 'chushiNumbers',
                    title: '初试人数',
                    width: 160
                }, {
                    field: 'fushiNumbers',
                    title: '复试人数',
                    width: 160
                }, {
                    field: 'bukaoNumbers',
                    title: '补考人数',
                    width: 160
                }, {
                    field: 'lilunPer',
                    title: '理论通过率',
                    width: 160
                },{
                    field: 'lilunPer',
                    title: '理论通过率',
                    width: 160
                },{
                    field: 'institutions',
                    title: '所属机构',
                    width: 160
                }
            ]]
        });

        layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'edit') { //编辑
                openDialog({
                    url: "/backend/security/examineeHall/detail?id=" + data.id,
                    area: ["85%", "90%"]
                });
            } else if (layEvent === 'setAll') { //编辑
                openDialog({
                    url: "/backend/security/examineeHall/setAll?id=" + data.id,
                    area: ["65%", "60%"]
                });
            }
        });

        $('#down').on('click', function (aLink) {
            var table = layui.table;
            var tab = table.cache.grid;
            var str = "考试人数,初试人数,复试人数,补考人数,理论通过率,实操通过率\n";
            $.each(tab, function (i, row) {
                str = str + row["numbers"] + "," + row["chushiNumbers"] + "," + row["fushiNumbers"] + "," + row["bukaoNumbers"] + "," + row["lilunPer"] + "," + row["shicaoPer"] + "\n";
            });
            str = encodeURIComponent(str);
            aLink.target.href = "data:text/csv;charset:utf-8,\ufeff" + str;
        });

        layui.form.on('submit(addBtn)', function () {
            openDialog({
                url: "/backend/security/examineeHall/detail",
                area: ["85%", "90%"]
            });
            return false;
        });


        layui.form.on('submit(searchBtn)', function (data) {
            tableIns.reload({
                where: data.field
            });
            return false;
        });
    })
</script>
</body>
</html>
